﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.BarCode
{
    class Standard2of5
    {
        private string[] S25_Code = { "11101010101110", "10111010101110", "11101110101010", "10101110101110", "11101011101010", "10111011101010", "10101011101110", "10101110111010", "11101010111010", "10111010111010" };

        private static volatile Standard2of5 instance;

        private static object syncRoot = new Object();

        public static Standard2of5 Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new Standard2of5();
                        }
                    }
                }
                return instance;
            }
        }

        public string GetBarCode(string barcode)
        {
            if (!Pixysoft.NumberCoder.Instance.IsInt64(barcode))
                throw new Exception("ES25-1: Numeric Data Only");

            string result = "11011010";

            foreach (char c in barcode)
            {
                result += S25_Code[Int32.Parse(c.ToString())];
            }//foreach

            //add ending bars
            result += "1101011";
            return result;
        }

    }
}
